package com.dymall.pay.controller;

import com.dymall.pay.domain.dto.PayApplyDTO;
import com.dymall.pay.domain.dto.PayOrderFormDTO;
import com.dymall.pay.service.PayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Api(tags = "支付相关接口")
@RestController
@RequestMapping("pay-orders")
@RequiredArgsConstructor
public class PayController {
    private final PayService payService;

    @ApiOperation("生成支付单")
    @PostMapping
    public String createPayOrder(@RequestBody PayApplyDTO payApplyDTO){
        return payService.createPayOrder(payApplyDTO);
    }

    @ApiOperation("尝试基于用户余额支付")
    @ApiImplicitParam(value = "支付单id", name = "id")
    @PostMapping("{id}")
    public void tryPayOrderByBalance(@PathVariable("id") Long id, @RequestBody PayOrderFormDTO payOrderFormDTO){
        payService.tryPayOrderByBalance(payOrderFormDTO);
    }
}
